package cn.jdy.djgaj.web;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.anquan.service.CompanySafeService;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.djgaj.sevice.DjgajAssociationsService;
import cn.jdy.djgaj.sevice.DjgajNewsService;
import cn.jdy.plugins.service.AdviceService;
import cn.jdy.plugins.service.BulletinService;
import cn.jdy.plugins.service.CitiesService;
import cn.jdy.plugins.service.CompanyService;
import cn.jdy.plugins.service.DocService;
import cn.jdy.plugins.service.NewspService;
import cn.jdy.plugins.service.RemoteAssociationsService;
import cn.jdy.plugins.service.ResearchService;
import cn.jdy.plugins.service.WorksService;

/**
 * @desc 网站首页
 * @author ningqian
 * @date   2016-10-26
 */
@RestController
@RequestMapping("/")
public class DjIndexCtrl extends BaseCtrl {

	@Autowired
	private CompanySafeService companySafeService; 
	
	@Autowired
	private CompanyService companyService;
	
	@Autowired
    private DjgajNewsService newsService;
	
	@Autowired
    private NewspService newspService;
	
	@Autowired
    private DocService docService;
	
	@Autowired
	  private DjgajAssociationsService associationsService;
	
	@Autowired
	  private RemoteAssociationsService remoteAssociationsService;
	
	@Autowired
	  private WorksService worksService;
	
	@Autowired
	  private BulletinService bulletinService;
	
	@Autowired
	  private ResearchService researchService;
	
	@Autowired
	  private AdviceService adviceService;
	@Autowired
	private CitiesService citiesService;
	
	/**
   * 首页-处理老链接
   */
//  @RequestMapping("index.html")
//  public ModelAndView forIndexold() {
//    return new ModelAndView("redirect:");// 将之前index.html 的权重传递给域名
//  }
// 

	  /**
	   * 临时
		 * 首页
		 */
		@RequestMapping("/index")
		public ModelAndView indexes() {
			ModelAndView mv = new ModelAndView("/index.jsp");
			return mv;
		}
			
	/**
	 * 东津公安分局
	 * 
	 * 首页
	 */
	@RequestMapping({"","index.html"})
	public ModelAndView index() {
		ModelAndView mv = new ModelAndView("/index.jsp");
		
		Date datetime = new Date();
		int weekdays = datetime.getDay();
		mv.addObject("weekdays",weekdays);//日一二三四五六=0123456
		
		String name1="zhzx",name2="xzdd",name3="jcjcdd",name4="zaxfdd";
		
		long[] bcnt=new long[4];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		bcnt[0]=this.associationsService.autilslev(name1);
		bcnt[1]=this.associationsService.autilslev(name2);
		bcnt[2]=this.associationsService.autilslev(name3);
		bcnt[3]=this.associationsService.autilslev(name4);
		//
		// 顺序对应4个单位
		int[] bindex={0,1,2,3};
		// 从小到大
		for(int i=0;i<bcnt.length-1;i++){   
               for(int j=i+1;j<bcnt.length;j++){   
                   if (bcnt[i]>bcnt[j]){   
                       long temp=bcnt[i];   
                       bcnt[i]=bcnt[j];   
                       bcnt[j]=temp; 
                       //下标
                       int tep=bindex[i];
                       bindex[i]=bindex[j];
                       bindex[j]=tep;
                  }   
            }  
       }  
		mv.addObject("bfirst",bcnt[3]);//最大数
		mv.addObject("bfirsta",this.aautils(bindex[3]));//对应单位名称
		mv.addObject("bsecond",bcnt[2]);
		mv.addObject("bseconda",this.aautils(bindex[2]));
		mv.addObject("bthird",bcnt[1]);
		mv.addObject("bthirda",this.aautils(bindex[1]));
		mv.addObject("bforth",bcnt[0]);
		mv.addObject("bfortha",this.aautils(bindex[0]));
		
		long[] cnt=new long[4];
		// cnt[0]+cnt[1]=cnt指挥中心？？？只能直接新增zhzx
		cnt[0]=this.associationsService.autils(name1);
		cnt[1]=this.associationsService.autils(name2);
		cnt[2]=this.associationsService.autils(name3);
		cnt[3]=this.associationsService.autils(name4);
		
		// 顺序对应4个单位
		int[] index={0,1,2,3};
		// 从小到大
		for(int i=0;i<cnt.length-1;i++){   
               for(int j=i+1;j<cnt.length;j++){   
                   if (cnt[i]>cnt[j]){   
                       long temp=cnt[i];   
                       cnt[i]=cnt[j];   
                       cnt[j]=temp; 
                       //下标
                       int tep=index[i];
                       index[i]=index[j];
                       index[j]=tep;
                  }   
            }  
       }  
		mv.addObject("first",cnt[3]);//最大数
		mv.addObject("firsta",this.aautils(index[3]));//对应单位名称
		mv.addObject("second",cnt[2]);
		mv.addObject("seconda",this.aautils(index[2]));
		mv.addObject("third",cnt[1]);
		mv.addObject("thirda",this.aautils(index[1]));
		mv.addObject("forth",cnt[0]);
		mv.addObject("fortha",this.aautils(index[0]));
		
		
		
		return mv;
	}


	
	  
	
	  /**
	   * 有效
	   * 市局
	   * 更多专题
	   */
	  @RequestMapping("more")
	  public ModelAndView loadMores() {
	    ModelAndView mv = new ModelAndView("/moreList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	  /**
	   * 有效
	   * 市局
	   * 更多应用系统
	   */
	  @RequestMapping("moreApps")
	  public ModelAndView loadMoreApps() {
	    ModelAndView mv = new ModelAndView("/appsList.jsp");
	  //襄阳市公安局，需要加入当前时间段周数
	  		Date datetime = new Date();
	  		int weekdays = datetime.getDay();
	  		mv.addObject("weekdays",weekdays);
	  		
	    return mv;
	  }
	  
	/**
	 * 清除掉全部数据缓存
	 * @return
	 */
	@RequestMapping("/clearCache")
	@CacheEvict(value = "cache1",allEntries=true)
	public String clearCache(){
	  return "ok...";
	}

  /**
   * 认证页面
   */
  @RequestMapping("verify")
  public ModelAndView verifyIndex() {
    ModelAndView mv = new ModelAndView("/verify.jsp");
    return mv;
  }
  
  /**
   * 个人中心 图片上传 upfileImg.jsp
   */
  @RequestMapping("upfileImg")
  public ModelAndView upfileImg() {
    ModelAndView mv = new ModelAndView("/upfileImg.jsp");
    return mv;
  }

  /**
   * 图片上传公共 upfileImg2.jsp
   */
  @RequestMapping("upfileImg2")
  public ModelAndView upfileImg2() {
    ModelAndView mv = new ModelAndView("/upfileImg2.jsp");
    return mv;
  }
  
  /**
   * 404页面
   */
  @RequestMapping("404")
  public ModelAndView notfond() {
    return new ModelAndView("/404.jsp");
  }
  /**
   * 500页面
   */
  @RequestMapping("500")
  public ModelAndView servicebusy() {
    return new ModelAndView("/500.jsp");
  }
  
  /**
   * 正在建设中页面
   */
  @RequestMapping("waiting")
  public ModelAndView waiting() {
    return new ModelAndView("/waiting.jsp");
  }
  
  
 
  /**
   * 有效：（utils）
   * 判断部门
   * @param index
   * @return
   */
  public String aautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "指挥中心";break;
	  case 1:name = "刑侦大队";break;
	  case 2:name = "基层基础大队";break;
	  case 3:name = "治安巡防大队";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断投稿地区
   * @param index
   * @return
   */
  public String raautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "法制室";break;
	  case 1:name = "刑侦大队";break;
	  case 2:name = "治安大队";break;
	  case 3:name = "国保大队";break;
	  case 4:name = "纪检督察";break;
	  case 5:name = "政工室";break;
	  case 6:name = "巡警大队";break;
	  case 7:name = "看守所";break;
	  case 8:name = "网安大队";break;
	  case 9:name = "出入境管理大队";break;
	  case 10:name = "经侦大队";break;
	  case 11:name = "控告申诉科";break;
	  case 12:name = "交警大队";break;
	  case 13:name = "指挥中心";break;
	  case 14:name = "消防大队";break;
	  case 15:name = "警务保障室";break;
	  case 16:name = "情报中心";break;
	  case 17:name = "行政拘留所";break;
	  case 18:name = "禁毒大队";break;
	  case 19:name = "科技信息科";break;
	  case 20:name = "反恐大队";break;
	  case 21:name = "合成作战室";break;
	  }
	  return name;
  }
  
  /**
   * 有效：（utils）
   * 判断访问地区
   * @param index
   * @return
   */
  public String baautils(int index){
	  String name=null;
	  switch(index){
	  case 0:name = "襄城";break;
	  case 1:name = "樊城";break;
	  case 2:name = "高新";break;
	  case 3:name = "襄东";break;
	  case 4:name = "东津新区";break;
	  case 5:name = "鱼梁洲";break;
	  case 6:name = "襄州区";break;
	  case 7:name = "枣阳市";break;
	  case 8:name = "宜城市";break;
	  case 9:name = "老河口市";break;
	  case 10:name = "南漳县";break;
	  case 11:name = "保康县";break;
	  case 12:name = "谷城县";break;
	  }
	  return name;
  }
  
}
